<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.Room, golf.Player"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>결과보기</title>
<meta name="generator" content="Namo WebEditor">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1>게임 결과</h1>
<%
DAO dao = DAO.getInstance();
int roomNo = (Integer)session.getAttribute("roomNo");
int charNo = (Integer)session.getAttribute("charNo");
//boolean result = dao.playerOneShot(charNo, roomNo, 1 );
Player[] players = dao.getPlayerList(roomNo);
Player me = dao.getPlayer(roomNo, charNo);
Room room = dao.getRoom(roomNo);
Room.Game game = room.getGame();
%>
<span style="font-size:9pt;">
<h3>게임 참가자 명단</h3>
<table cellspacing="0" border="1" bordercolordark="white" bordercolorlight="black" width="80%">
	<tr>
		<td width="150">캐릭터명</td>
		<td width="80">모델명</td>
		<td width="50">등급</td>
		<td width="20">레벨</td>
		<td width="20">경험치</td>
		<td width="50">게임 후 엔지</td>
		<td width="50">참가여부</td>
	</tr>
	<%for( int i = 0; i < players.length; i++ ){ %>
	
	<tr>
		<td width="150"><%=players[i].getCharacter().getName() %></td>
		<td width="80"><%=players[i].getCharacter().getModel().getName() %></td>
		<td width="50"><%=players[i].getCharacter().getGrade().getName() %></td>
		<td width="20"><%=players[i].getCharacter().getLevel() %></td>
		<td width="20"><%=players[i].getCharacter().getExp() %></td>
		<td width="50"><%=players[i].getCharacter().getEnzi() %></td>
		<td width="50"><%=players[i].getPlay_yn() %></td>
	</tr>	
	<%} %>
</table>
<%
int pre_enzi = Integer.parseInt(request.getParameter("enzi"));
int pre_exp = Integer.parseInt(request.getParameter("exp"));
int pre_level = Integer.parseInt(request.getParameter("level"));
int pre_distance = Integer.parseInt(request.getParameter("high_distance"));
int pre_hio = Integer.parseInt(request.getParameter("hole_in_one"));
Player pre_me = (Player)session.getAttribute("pre_player_status");
session.setAttribute("pre_player_status", null);

%>
<h3>게임 후 [<%=me.getCharacter().getName() %>] 상태 변화</h3>
<table cellspacing="0" border="1" bordercolordark="white" bordercolorlight="black" width="80%">
	<tr>
		<td width="100">&nbsp;</td>
		<td width="150">게임 전</td>
		<td width="150">게임 후</td>
	</tr>
	<tr>
		<td width="100">엔지</td>
		<td><%=pre_me.getCharacter().getEnzi() %></td>
		<td><%=me.getCharacter().getEnzi() %></td>
	</tr>
	<tr>
		<td width="100">경험치</td>
		<td><%=pre_me.getCharacter().getExp() %></td>
		<td><%=me.getCharacter().getExp() %></td>
	</tr>
	<tr>
		<td width="100">레벨</td>
		<td><%=pre_me.getCharacter().getLevel() %></td>
		<td><%=me.getCharacter().getLevel() %></td>
	</tr>
	<tr>
		<td width="100">최대비거리</td>
		<td><%=pre_me.getCharacter().getHigh_distance() %></td>
		<td><%=me.getCharacter().getHigh_distance() %></td>
	</tr>
	<tr>
		<td width="100">홀인원횟수</td>
		<td><%=pre_me.getCharacter().getHoleinone_cnt() %></td>
		<td><%=me.getCharacter().getHoleinone_cnt() %></td>
	</tr>	
</table>
</span>


<p><span style="font-size:9pt;">&nbsp;</span></p>
<p><span style="font-size:9pt;">&nbsp;</span></p>
<p><span style="font-size:9pt;">&nbsp;</span></p>
				<div style="height:400px;overflow:auto;">
				<table id="chat">
				</table>
				</div>
<script>
function addmessage()
{
  new Ajax.Request('../post/postChattingAddMsg.jsp',
  {
     method: 'post',
     parameters: $('form').serialize(),
     onSuccess: function( transport ) {
       $('msgType').value = '';
     }
  } );
}
</script>
<form name="form">
            <td width="78"><select name="chatCD" size="1">
                    <option value="CT001">방채팅</option>
                    <option value="CT002">귓속말</option>
                    <option value="CT003">길드채팅</option>
</select></td>
            <td width="147">
                <p><span style="font-size:9pt;"><input type="text" name="toWho" maxlength="20" size="20"></span></p>
            </td>
            <td width="482">
                <p><span style="font-size:9pt;"><input type="text" name="chatType" id="msgType" size="75"></span></p>
            </td>
            <td width="10">
                <p><span style="font-size:9pt;"><button onclick="addmessage()">Add</button></span></p>
            </td>
        </tr>
    </table>
</form>

<script>
var lastid = 0;
function getMessages()
{
  new Ajax.Request( '../post/postChattingMessage.jsp?lastid='+lastid, {
	  onSuccess: function( transport ) {
      var messages = transport.responseXML.getElementsByTagName( 'message' );
      for( var i = 0; i < messages.length; i++ )
      {
		var message = messages[i].firstChild.nodeValue;
		var id = parseInt(messages[i].getAttribute('id'));
		var serverNo = messages[i].getAttribute('serverNo');
		var senderCharNo = messages[i].getAttribute('senderCharNo');
		var senderName = messages[i].getAttribute('senderName');
		var chatCdClassify = messages[i].getAttribute("chatCdClassify");
		var chatCD = messages[i].getAttribute('chatCD');
		if(chatCD == "CT001") {
			chatCD = "방채팅";
		} else if(chatCD == "CT002") {
			chatCD = "귓속말";
		} else {
			chatCD = "길드채팅";
		}
        if ( id > lastid )
        {
          var elTR = $('chat').insertRow( -1 );
          var elTD1 = elTR.insertCell( -1 );
          elTD1.appendChild( document.createTextNode( "[" + senderName + "]") );
          var elTD2 = elTR.insertCell( -1 );
          elTD2.appendChild( document.createTextNode( "[" + chatCD + "] : " ) );
          var elTD3 = elTR.insertCell( -1 );
          elTD2.appendChild( document.createTextNode( message ) );

          lastid = id;
        }
      }
      window.setTimeout( getMessages, 1000 );
    }
  } );
}
getMessages();
</script>

<p><span style="font-size:9pt;">&nbsp;</span></p>
<p><span style="font-size:9pt;">최종적인 결과만 보여주도록 하자 ㅠㅠ</span></p>
<p><span style="font-size:9pt;">쒯이다 이거.</span></p>
</body>

</html>